package com.automannn.websocketmqtt.websocketNodeA.pubsub.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

/**
 * @author chenkh
 * @time 2020/10/15 16:24
 */
@Component
public class WsRedisSubscriber implements MessageListener {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        RedisSerializer<String> serializer = redisTemplate.getValueSerializer();
        String body= serializer.deserialize(message.getBody());
        System.out.println("主题:"+new String(message.getChannel()));
        System.out.println("消息内容："+body);
    }
}
